<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
		<base href="<%=basePath%>">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>业务类别维护</title>
		<meta name="description" content="" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		
		<link rel="stylesheet" href="static/ace/css/bootstrap.css" />
		<link rel="stylesheet" href="static/ace/css/font-awesome.css" />
		
		<!-- text fonts -->
		<link rel="stylesheet" href="static/ace/css/ace-fonts.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
		<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
		<script type="text/javascript">
			$(top.hangge());
		</script>
</head>
<body class="no-skin" id="bodyId">

<div class="main-container" id="main-container">
	<div class="main-content">
		<div class="main-content-inner">
			<div class="page-content">
				<div class="row">
					<div class="col-xs-12">
					<form action="<%=path%>/common/index" method="post" name="businessForm" id="businessForm">
						<div id="test">
<!-- 						<input type="button"  class="btn btn-success"   value="保存" id="deleteTable" onclick="edit();"/> -->
							<table style="width:100%;">
								<tr>
									<td style="vertical-align:top;">
										<a title="新增" class="btn btn-mini btn-info"
										   onclick="addRow()">
											<i class="ace-icon fa bigger-120">新增</i>
										</a>
									</td>

									<td style="vertical-align:top;">
										<a title="保存" class="btn btn-mini btn-info"style="right:350px;"
										   onclick="edit();">
											<i class="ace-icon fa bigger-120">保存</i>
										</a>
									</td>
									<td style="vertical-align:top;">
										<a title="删除" class="btn btn-mini btn-info"style="right:701px;"
										   onclick="deleteInfo();">
											<i class="ace-icon fa bigger-120">删除</i>
										</a>
									</td>
								</tr>
							</table>
						
						
						<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
							
							<thead>
								<tr id="test1">
									<th class="center" style="width:35px;">
									<label class="pos-rel"><input type="checkbox" class="ace" id="zcheckbox" /><span class="lbl"></span></label>
									</th>
									
									<th class="center" style="width:50px;"id="option0">序号</th>
									<th class="center"id="option2"style="width:300px;">业务类别中文名</th>
									<th class="center"id="option3"style="width:300px;">业务类别编码</th>
				 					<th class="center"id="option4"style="width:300px;">排列顺序</th>
									<th class="center"id="option5"style="width:100px;">是否可用</th>
								</tr>
							</thead>
							<tbody>
							<c:choose>
								<c:when test="${not empty businessType}">
									<c:forEach items="${businessType}" var="businessType" varStatus="vs">		
										<tr id="trId">
										<td class="dbclicktd" style="width: 30px;">
												<label><input type='checkbox' value="${businessType.ID }" id="ids"name="ids"class="ace"/><span class="lbl"></span></label>
												
											</td>
											<td class="dbclicktd"  id="td1">${businessType.SERIAL}</td>
											<td class='dbclicktd' style="width: 30px;"id="td2">${businessType.BUSINESS_TYPE_CHINESE_NAME}</td>
											<td class="dbclicktd" id="td3">${businessType.BUSINESS_TYPE_CODE}</td>
											<td class="dbclicktd"id="td4">${businessType.ARRANGEMENT_ORDER}</td>
											<c:if test="${businessType.ENABLE ==1}">
											<td class="dbclicktd"id="td5">是</td>
											</c:if>
											<c:if test="${businessType.ENABLE ==0}">
											<td class="dbclicktd" id="td5">否</td>
											</c:if>
											
										</tr>
										
									
									</c:forEach>
<!-- 									<div class="hidden-sm hidden-xs btn-group"> -->
<%-- 											<a class="btn btn-xs btn-success" title="编辑" onclick="editUser('${user.USER_ID}');"> --%>
<!-- 														<i class="ace-icon fa fa-pencil-square-o bigger-120" title="编辑"></i> -->
<!-- 													</a> -->
<!-- 												</div> -->
								</c:when>
							</c:choose>
							</tbody>
						</table>
						</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

</body>
<script>


	
$("#main-container").click(function(){
	 $("#tt1").blur(function(){
			$(this).closest("td").text($(this).val())
			
	    	});
	    $("#tt2").blur(function(){
			$(this).closest("td").text($(this).val())
	    	});
	    $("#tt3").blur(function(){
			$(this).closest("td").text($(this).val())
	    	});
	    $("#tt4").blur(function(){
			$(this).closest("td").text($(this).val())

	    	});
    });
// function saveData(){
// //  var id = $("#simple-table tbody tr").find("td").first().find("label").find("#ids")[0].value;
//  var businessTypeChineseName = $("#tt1").val();
//  var businessTypeCode = $("#tt2").val();
//  var arrangementOrder = $("#tt3").val();
//  var enable = $("#tt4").val();

// 	$.ajax({
// 		type: "POST",
<%-- 		url: '<%=basePath%>businessTypeMaintain/saveBusinessTypeMainTain', --%>
//  		data: {SERIAL:rowCount,BUSINESS_TYPE_CHINESE_NAME:businessTypeChineseName,BUSINESS_TYPE_CODE:businessTypeCode,ARRANGEMENT_ORDER:arrangementOrder,ENABLE:enable},
// 		dataType:'json',
// 		cache: false,
// 		success: function(data){
// 		}
// 	});
// }
var rowCount=$("#simple-table").find("tr").length-1;  //获取行数  
  
//添加行  
function addRow(){  
    rowCount++;  
    var newRow='<tr id="option'+rowCount+'"><td class="dbclicktd"><label class="pos-rel"><input type="checkbox"name="ids"/></label></td><td class="dbclicktd">'+rowCount+'</td><td class="oz-property" ><input type="text" id="tt1"  style="width:300px"></td><td class="dbclicktd" ><input type="text" id="tt2" style="width:300px"><td class="dbclicktd" ><input type="text"  id="tt3" style="width:300px"><td class="dbclicktd" ><input type="text" id="tt4"  style="width:100px"></td></td></td></tr>';  
    $('#simple-table').append(newRow); 
   
// 	saveData();
}
$("#simple-table").find(".dbclicktd").bind("dblclick", function () {
    var input = "<input type='text' id='temp' style='width:320px;' value=" + $(this).text() + " >";
//     $(this).text();
    $(this).text("");
    $(this).append(input);
    $("#temp").focus();
    $("#temp").blur(function () {
        if ($(this).val() == "") {
            $(this).remove();
        } else {
            $(this).closest("td").text($(this).val());
        }
    });
});
function edit(){
var trList = [];
var $simpleTabletr = $("#simple-table tbody tr");
var list = {}
for(var i=0,len=$simpleTabletr.length;i<len;i++){
	var objTr = $simpleTabletr[i];
	
// 	var flag = $(objTr).find("td").first().find("label").find("#ids")[0].checked;
// 	if(flag){
// 		alert("1");
		trList.push(objTr);
// 	}
}
//传到后台的data json格式
var data = [];
 for(var i=0,size=trList.length;i<size;i++){
	var $tds = $(trList[i]).find("td");
	//id
	var id = $($tds[0]).find("label").find("input[name='ids']")[0].value;
	//序号
	var SERIAL = $($tds[1]).text();
	//业务类别中文名
	var CHINESE_NAME = $($tds[2]).text();
	//业务类别编码
	var TYPE_CODE = $($tds[3]).text();
	//排列顺序
	var ORDER = $($tds[4]).text();
	//是否可用
	var isEnable = $($tds[5]).text(); 
	
	var item = {};
// 	item.你的实体字段名 = 具体的值;
// 	if(id!==null){
		item.ID = id.trim();
// 	}
	
	item.SERIAL = SERIAL;
	item.BUSINESS_TYPE_CHINESE_NAME = CHINESE_NAME;
	item.BUSINESS_TYPE_CODE = TYPE_CODE;
	item.ARRANGEMENT_ORDER = ORDER;
	if(isEnable=="是"){
		item.ENABLE = "1"
	}else{
		item.ENABLE = "0"
	}
// 	item.ENABLE = isEnable
	data.push(item)
}
 var dataStr = JSON.stringify(data);

 $.ajax({
             type: "POST",
             url: '<%=basePath%>businessTypeMaintain/updateBusinessTypeMaintain',
             data: {dataJsonStr:dataStr},
             dataType: 'json',
             //beforeSend: validateData,
             cache: false,
             success: function (data) {
            	 window.location.reload();
             }
         });

}
function deleteInfo(){
	var trList = [];
	var $simpleTabletr = $("#simple-table tbody tr");
	var list = {}
	for(var i=0,len=$simpleTabletr.length;i<len;i++){
		
		var objTr = $simpleTabletr[i];
		
		var flag = $(objTr).find("td").first().find("label").find("#ids")[0].checked;
		if(flag){
			trList.push(objTr);
		}
	}
	//传到后台的data json格式
	var data = [];
	 for(var i=0,size=trList.length;i<size;i++){
		var $tds = $(trList[i]).find("td");
		//id
		var id = $($tds[0]).find("label").find("input[name='ids']")[0].value;
		var item = {};
		item.ID = id.trim();
		data.push(item)
	}
	 var dataStr = JSON.stringify(data);
	 $.ajax({
         type: "POST",
         url: '<%=basePath%>businessTypeMaintain/deleteBusinessTypeMaintain',
         data: {dataJsonStr:dataStr},
         dataType: 'json',
         //beforeSend: validateData,
         cache: false,
         success: function (data) {
        	 window.location.reload();
        	 
         }
     });
}

</script>
</html>